package com.kafka.kafka.study;

import com.kafka.kafka.utils.PropertiesUtils;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * Project: tobe-better-coder
 * Package: com.kafka.kafka.study
 *
 * @author : Mr.xu
 * @date : 2023/9/10 15:19
 */
public class CustomProducerCallBackPartitions {

    public static void main(String[] args) {
        Properties properties = PropertiesUtils.getKafkaProperties("node1:9092,node2:9092");

        KafkaProducer<String, String> kafkaProducer = new KafkaProducer<>(properties);

        kafkaProducer.send(new ProducerRecord<>("kafka",4,"", "callBack111"), (recordMetadata, e) -> {
            if (null == e) {
                System.out.println("topic = " + recordMetadata.topic() + " 分区 = " + recordMetadata.partition());
            }
        });

        System.out.println(111);
        //没有这个消息发不出去
        kafkaProducer.close();

    }
}